// pages/ticketsList/ticketsList.js
const util = require('../../utils/util.js')
const app = getApp();
const cloudUrl = app.globalData.cloudUrl;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    cloudUrl:cloudUrl,
    ticketsList:[{id:1, name:"松阳端午茶", price:30, oldPrice:30, sellNum:2},{id:1, name:"黄家大院景区门票", price:30, oldPrice:30, sellNum:2},{id:1, name:"松阳端午茶", price:30, oldPrice:30, sellNum:2},{id:1, name:"黄家大院景区门票2", price:30, oldPrice:30, sellNum:2},{id:1, name:"松阳端午茶", price:30, oldPrice:30, sellNum:2},{id:1, name:"松阳端午茶", price:30, oldPrice:30, sellNum:2},{id:1, name:"松阳端午茶", price:30, oldPrice:30, sellNum:2},{id:1, name:"松阳端午茶", price:30, oldPrice:30, sellNum:2}],
    tempArr:[],
    hotShopUrl:cloudUrl+"canyinIcon.png",
    inputTxt:"",
    isTipsShow:false,
    curTicketInfo:{},
    curSwipers:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.setNavigationBarTitle({
      title: '自助购票',
    })

    const app = getApp();
    const list = app.globalData.ticketsList;
    this.data.tempArr = list.concat();
    this.setData({tempArr:this.data.tempArr,ticketsList:list});
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    
  },
  onNotesEvent(e){
    //console.log(e);
    if(e.detail.type == "close"){
      this.setData({isTipsShow:false});
    }
  },
  onNotesClick(e){
    const idx = e.currentTarget.dataset.index;
    console.log("idx="+idx);
    var curInfo = this.data.tempArr[idx];
    var swipers = curInfo.swipers;
    curInfo = JSON.stringify(curInfo);
    //console.log(curInfo);
    this.setData({curTicketInfo:curInfo,curSwipers:swipers});
    this.setData({isTipsShow:!this.data.isTipsShow});
  },
  onBuyClick(e){
    const idx = e.currentTarget.dataset.index;
    console.log("idx="+idx);
    var curInfo = this.data.tempArr[idx];
    curInfo = JSON.stringify(curInfo);
    util.gotoTicketsBuyPage(curInfo);//
  },
  onInputChange(e){
    console.log(e);
    this.data.inputTxt = e.detail.value;
  },
  onSearchClick(e){
    var slist = this.data.ticketsList;
    var str = "";
    this.data.tempArr.length = 0;
    if(this.data.inputTxt != ""){
      for(var i=0; i<slist.length; i++){
        str = slist[i].name;
        if(str.indexOf(this.data.inputTxt) != -1){
          this.data.tempArr.push(slist[i]);
        }
      }
    }
    else{
      this.data.tempArr = this.data.ticketsList.concat();
    }
    this.setData(this.data);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})